#!/usr/bin/env node

const fs = require('fs');
const src= process.argv[2],
  dst = process.argv[3];

if(!fs.existsSync(src)){
  console.error('%s NOT EXIST',src);
  process.exit(1);
}
if(!fs.statSync(src).isFile()){
  console.error('%s NOT A FILE',src);
  process.exit(2);
}
if(typeof dst === 'undefined'){
  console.error('dst IS UNDEFINED');
  process.exit(3);
}
//复制内容
let stm = fs.createReadStream(src).pipe(fs.createWriteStream(dst));

//权限拷贝
stm.on('close',()=>{
  fs.chmodSync(dst,fs.statSync(src).mode);
});

//
